package net.form.processing;

import java.awt.Color;
import java.util.List;

public class ClusterVector {

	protected int id;
	List<Cluster1> properties;

	protected String nameClass;
	
	protected int tolerancePercentage;

	public ClusterVector(int id, String nameClass, List<Cluster1> properties,int tolerancePercentage) {
		this.id = id;
		this.nameClass = nameClass;
		this.properties = properties;
		this.tolerancePercentage=tolerancePercentage;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getColor() {
		return getColor(id);
	}

	public void addPropertie(Cluster1 c) {
		properties.add(c);

	}

	public List<Cluster1> getProperties() {
		return properties;
	}

	public void setProperties(List<Cluster1> properties) {
		this.properties = properties;
	}
	
	public int getTolerancePercentage() {
		return tolerancePercentage;
	}

	public void setTolerancePercentage(int tolerancePercentage) {
		this.tolerancePercentage = tolerancePercentage;
	}

	public int getColor(int id) {
		int color = 0;
		switch (id + 1) {
		case 1:
			color = Color.red.getRGB();
			break;
		case 2:
			color = Color.blue.getRGB();
			break;
		case 3:
			color = Color.green.getRGB();
			break;
		case 4:
			color = Color.yellow.getRGB();
			break;
		case 5:
			color = Color.pink.getRGB();
			break;
		case 6:
			color = Color.cyan.getRGB();
			break;
		case 7:
			color = Color.magenta.getRGB();
			break;
		case 8:
			color = Color.black.getRGB();
			break;
		case 9:
			color = Color.gray.getRGB();
			break;
		case 10:
			color = Color.orange.getRGB();
			break;
		case 11:
			color = Color.white.getRGB();
			break;
		default:
			color = Math.round((id * 5 + 10));
			break;
		}
		return color;
	}

	public String getType() {
		return "Cluster Vector";
	}

	public Object clone() {
		ClusterVector clase = new ClusterVector(this.id, this.nameClass,
				this.properties,this.tolerancePercentage);
		return clase;
	}

	public double distance(List<Cluster1> valor) {
		double dif = 0;
		for (int i = 0; i < properties.size(); i++) {
			Cluster1 cv = properties.get(i);
			double d1 = cv.getValue();
			double d2 = getValor(valor,cv.getRasgo());
			dif = dif + Math.abs(d1 - d2);
		}
		return dif;
	}

	protected double getValor(List<Cluster1> valor, String rasgo) {
		double result = 0;
		boolean finish = false;
		int i = 0;
		while (valor != null && !finish) {
			if (valor.get(i).getRasgo().equals(rasgo)) {
				finish = true;
				result = valor.get(i).getValue();
			}
			i++;
		}
		return result;
	}

	public void removeValue(List<Cluster1> valor) {
		for (int i = 0; i < properties.size(); i++) {
			Cluster1 cv = properties.get(i);
//			cv.removeValue(valor.get(i).doubleValue());
			cv.removeValue(getValor(valor,cv.getRasgo()));
		}
	}

	public void addValue(List<Cluster1> valor) {
		for (int i = 0; i < properties.size(); i++) {
			Cluster1 cv = properties.get(i);
//			cv.addValue(valor.get(i).doubleValue());
			cv.addValue(getValor(valor,cv.getRasgo()));
		}
	}

	public void clear() {
		for (int i = 0; i < properties.size(); i++) {
			Cluster1 cv = properties.get(i);
			cv.clear();
		}
	}

}
